#!/bin/sh

FILE=${!#}
sed 's/</\n</g' $FILE > ${FILE}.tmp
rm $FILE
mv ${FILE}.tmp $FILE
for i in $(seq 1 100); do
  ./html2text.py $* 2>html2text.log
  if [ $? -eq 0 ]; then
    break
  fi
  line=$(grep 'HTMLParser.HTMLParseError' html2text.log | sed 's/.*line \([0-9]*\),.*/\1/')
  if [ -z "$line" ]; then
    break
  fi
  sed "${line}d" $FILE > ${FILE}.tmp 
  rm $FILE
  mv ${FILE}.tmp $FILE
done

